﻿using System.Collections.Generic;
using Engine;
using Engine.Graphics;

namespace Game
{
    public class AbstractSalpling : CrossBlock
    {
        public enum PlantsType
        {
            Sakura,
            Blue
        }

        public const int Index = 302;

        public Texture2D m_texture;

        public string m_textureRoute;

        public const int Num = 2;

        public double NextUpdateTime;

        public static int[] m_fruitNames = new int[2] { 305, 305 };

        public static string[] m_textureNames = new string[2] { "Textures/SakuraTree/sakurasapling", "Textures/Plants/Apple/apple_sapling" };

        public static string[] m_displayName = new string[2] { "樱花树苗", "苹果树苗" };

        public static string[] m_descriptions = new string[2] { "树苗用于种植树木。您可以通过从树木的叶子上手工制作来获得它们。种植时，请小心地将树苗放在光线充足，湿度充足且温度正确的地方。使用湿度计和温度计测量这些量。橡树喜欢温暖，白桦树喜欢常温，金合欢树喜欢凉爽，云杉树喜欢寒冷，樱花树喜欢温暖。所有树木都需要大量的水。如果您将树苗种在错误的位置，它将枯萎成干燥的灌木丛。", "树苗用于种植树木。您可以通过从树木的叶子或者果子上手工制作来获得它们。种植时，请小心地将树苗放在光线充足，湿度充足且温度正确的地方。使用湿度计和温度计测量这些量。橡树喜欢温暖，白桦树喜欢常温，金合欢树喜欢凉爽，云杉树喜欢寒冷，樱花树喜欢温暖，苹果树喜欢寒冷。所有树木都需要大量的水。如果您将树苗种在错误的位置，它将枯萎成干燥的灌木丛。" };

        public override IEnumerable<int> GetCreativeValues()
        {
            List<int> list = new List<int>();
            foreach (int enumValue in EnumUtils.GetEnumValues(typeof(PlantsType)))
            {
                list.Add(Terrain.MakeBlockValue(BlockIndex, 0, enumValue));
            }

            return list;
        }

        public AbstractSalpling()
        {
            DefaultIconViewOffset = new Vector3(0f, 0f, 1f);
            DefaultCategory = "Plants";
            CraftingId = "FruitPlants";
            DisplayOrder = 95;
            DefaultCreativeData = 0;
            IsPlaceable = true;
            IsPlacementTransparent = true;
            IsTransparent = true;
            FirstPersonScale = 0.4f;
            FirstPersonOffset = new Vector3(0.5f, -0.5f, -0.6f);
            FirstPersonRotation = new Vector3(0f, 0f, 0f);
            InHandScale = 0.3f;
            InHandOffset = new Vector3(0f, 0.12f, 0f);
            InHandRotation = new Vector3(100f, 0f, 0f);
            IsCollidable = false;
            DigResilience = 0.1f;
            DigMethod = BlockDigMethod.Hack;
            DefaultSoundMaterialName = "Grass";
        }

        public override int GetTextureSlotCount(int value)
        {
            return 1;
        }

        public override int GetFaceTextureSlot(int face, int value)
        {
            if (face == -1)
            {
                return 0;
            }

            return 2;
        }

        public override string GetDisplayName(SubsystemTerrain subsystemTerrain, int value)
        {
            int num = Terrain.ExtractData(value);
            return m_displayName[num];
        }

        public override string GetDescription(int value)
        {
            return m_descriptions[Terrain.ExtractData(value)];
        }

        public override void Initialize()
        {
            for (int i = 0; i < 2; i++)
            {
                m_texture = ContentManager.Get<Texture2D>(m_textureNames[i]);
            }
        }

        public override void GenerateTerrainVertices(BlockGeometryGenerator generator, TerrainGeometry geometry, int value, int x, int y, int z)
        {
            int num = Terrain.ExtractData(value);
            string name = m_textureNames[num];
            m_texture = ContentManager.Get<Texture2D>(name);
            Color color = new Color(255, 255, 255);
            generator.GenerateCrossfaceVertices(this, value, x, y, z, color, GetFaceTextureSlot(1, value), geometry.GetGeometry(m_texture).SubsetAlphaTest);
        }

        public override void DrawBlock(PrimitivesRenderer3D primitivesRenderer, int value, Color color, float size, ref Matrix matrix, DrawBlockEnvironmentData environmentData)
        {
            int num = Terrain.ExtractData(value);
            string name = m_textureNames[num];
            m_texture = ContentManager.Get<Texture2D>(name);
            BlocksManager.DrawFlatOrImageExtrusionBlock(primitivesRenderer, value, size, ref matrix, m_texture, color, isEmissive: false, environmentData);
        }
    }
}